home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / include / window.h < prev   
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.9 KB  |  274 lines

  1. // $Id: window.h 1.5 1998/04/08 15:13:40 dlorre Exp dlorre $
  2. #if !defined( CLASS_WINDOW_H )
  3. #define CLASS_WINDOW_H 1
  4.  
  5.  
  6. #if !defined( EXEC_TYPES_H )
  7. #include <exec/types.h>
  8. #endif
  9.  
  10. #if !defined( GRAPHICS_TYPES_H )
  11. #include <graphics/gfxbase.h>
  12. #endif
  13.  
  14. #if !defined( GRAPHICS_GFXMACROS_H )
  15. #include <graphics/gfxmacros.h>
  16. #endif
  17.  
  18. #if !defined( INTUITION_GADGETCLASS_H )
  19. #include <intuition/gadgetclass.h>
  20. #endif
  21.  
  22. #if !defined( LIBRARIES_GADTOOLS_H )
  23. #include <libraries/gadtools.h>
  24. #endif
  25.  
  26. #ifndef CLASS_SLIST_H
  27. #include "slist.h"
  28. #endif
  29.  
  30. #include "rectangle.h"
  31. #include "screen.h"
  32. #include "locale.h"
  33.  
  34. #ifndef CLASS_GADGETLIST_H
  35. #include "gadgetlist.h"
  36. #endif
  37.  
  38. #ifndef CLASS_GADGET_H
  39. class window ;
  40. #include "gadgets/gadget.h"
  41. #endif
  42.  
  43. #ifndef CLASS_STRING_H
  44. #include "gadgets/string.h"
  45. #endif
  46.  
  47. #ifdef open
  48. #undef open
  49. #endif
  50.  
  51. #ifdef close
  52. #undef close
  53. #endif
  54.  
  55. class menustate {
  56. public:
  57.     MenuItem    *item ;
  58.     BOOL        enable ;
  59.     BOOL        checked ;
  60.     menustate() : item(NULL), enable(TRUE), checked(FALSE) {}
  61. } ;
  62.  
  63. class window ;
  64.  
  65. class wlink : public nlink
  66. {
  67. public:
  68.     window *win ;
  69. } ;
  70.  
  71. // ========================================================================
  72. // ========================== WINDOW CLASS ================================
  73. // ========================================================================
  74.  
  75.  
  76.  
  77. class window : public rectangle {
  78. friend class gadgetlist ;
  79. private:
  80.     TagItem     *tags ;
  81.     Region      *clipregion ;
  82.     Rectangle   *cliprect ;
  83.  
  84.     short       awidth ;
  85.     short       aheight ;
  86.     int         asize ;
  87.     WORD        *areaBuffer ;
  88.     UBYTE       *tmpBuffer;     // PLANEPTR
  89.     BitMap      *tmpBitMap ;
  90.     AreaInfo    *areaInfo ;
  91.     TmpRas      *tmpRas ;
  92.     short       drawmode ;
  93.     RastPort    *bgrp ;
  94.     BitMap      *bgbm ;
  95.     wlink       link ;
  96. protected:
  97.     gadgetlist  *g ;            // the gadgets attached to this window
  98.     void        (*reqfunc)(long, unsigned long, unsigned short) ;
  99.  
  100.     ULONG       idcmp ;         // the IDCMP flags
  101.     BOOL        hasgadgets ;    // window contains gadgets
  102.     BOOL        hasmenus ;      // window contains menus
  103.     BOOL        selfmsg ;       // the MsgPort is not shared
  104. public:
  105.     screen      *ws ;
  106.     Window      *win ;          // useful pointers
  107.     MsgPort     *mp ;
  108.     Menu        *menu ;
  109.     RastPort    *rp ;
  110.  
  111.     BOOL        active ;        // user did not request for closing
  112.     BOOL        initok ;        // open window succeeds
  113.     ULONG       signal ;        // the MsgPort signal bit
  114.  
  115.     char        sname[256] ;    // storage (name in dialog box)
  116.     BOOL        okflag ;        // user accept dialog box
  117.     BOOL        applique ;      // do the changes now
  118.     LONG        emode ;         // extended mode set to 1 if special action
  119. public:
  120.     window(short l, short t, short w, short h) ;
  121.     virtual ~window() ;
  122. protected:
  123.     // Standard Gadget Routines
  124.     virtual void fok(gadget *g, unsigned long classe, unsigned short code) ;
  125.     virtual void fcancel(gadget *g, unsigned long classe, unsigned short code) ;
  126.     virtual void fapply(gadget *g, unsigned long classe, unsigned short code) ;
  127.     virtual void fname(gadget *g, unsigned long classe, unsigned short code) ;
  128.     virtual void handlevkey(USHORT code) ;
  129.     virtual void handlerawkey(USHORT code) ;
  130.     virtual void handlemousebuttons(USHORT code, WORD x, WORD y, UWORD qualifier) ;
  131. public:
  132.     virtual void open(screen *) ;
  133.     virtual void close() ;
  134.     virtual void simpleevent(IntuiMessage *msg) ;
  135.     virtual void otext( long x, long y, const char *string ) ;
  136. protected:
  137.     void _open(MsgPort *, ULONG, ULONG, ...) ;
  138.     void _open(MsgPort *, ULONG, TagItem *) ;
  139.  
  140.     void strip() ;
  141.     void stripimsg() ;
  142.     void resetidcmp() ;
  143.  
  144. public:
  145.     void prepbox(BOOL center=FALSE) ;    // Initialization routine
  146.     void eventloop() ;
  147.     void processevents(IntuiMessage *msg) ;
  148.     void setfunc(void (*func)(long , unsigned long, unsigned short)) ;
  149.  
  150.     // Window management functions
  151.     void move(short dx, short dy=0) ;
  152.     void size(short dw, short dh=0) ;
  153.     void box(short x, short y, short w, short h) ;
  154.     void limits(short wmin, short hmin, short wmax, short hmax) ;
  155.     void titles(const char *wt, const char *st) ;
  156.     void activate() ;
  157.     void front() ;
  158.     void back() ;
  159.  
  160.     // Gadtools & Menus routines
  161.     void recessedbox(short x, short y, short w, short h) ;
  162.     void bevelbox(short x, short y, short w, short h) ;
  163.     void setmenus(struct NewMenu *menu1, ...) ;
  164.     void expandmenu(Menu *, NewMenu *extmenu) ;
  165.     void menuchanges(menustate *, LONG count) ;
  166.     MenuItem *itemaddress( unsigned long menuNumber ) ;
  167.     MenuItem *itemaddress(LONG m, LONG i, LONG s) ;
  168.     void clearmenustrip(void) ;
  169.     BOOL resetmenustrip(void) ;
  170.  
  171.     // Gfx routines
  172.     void pmove(long x, long y) ;                    // Move(rp, ...)
  173.     void draw(long x, long y) ;                     // Draw(rp, ...)
  174.     void polydraw(long count, WORD *polyTable) ;
  175.     void rectfill(long xMin, long yMin, long xMax, long yMax) ;
  176.     void eraserect(long xMin, long yMin, long xMax, long yMax ) ;
  177.     void setapen(unsigned long pen) ;
  178.     void setbpen(unsigned long pen) ;
  179.     void setopen(unsigned long pen) ;
  180.     void setrast(unsigned long pen) ;
  181.     void setdrmd(unsigned long drawMode) ;
  182.     void setdrpt(UWORD pattern) ;
  183.     void setafpt(const UWORD *pattern, BYTE count) ;
  184.     short textlength(const char *string, unsigned long count ) ;
  185.     void text( const char *string, unsigned long count ) ;
  186.     unsigned long textfit(const char *string, unsigned long strLen,
  187.         struct TextExtent *textExtent, struct TextExtent *constrainingExtent,
  188.         long strDirection, unsigned long constrainingBitWidth,
  189.         unsigned long constrainingBitHeight ) ;
  190.     void setfont(TextFont *font) ;
  191.  
  192.     // Intuition Drawing Routines
  193.     void printitext(IntuiText *iText, long left, long top ) ;
  194.     void drawborder( Border *border, long leftOffset, long topOffset ) ;
  195.     void drawimage( struct Image *image, long leftOffset, long topOffset ) ;
  196.     void eraseimage( struct Image *image, long leftOffset, long topOffset ) ;
  197.  
  198.     // Clip Routines
  199.     int newregion(void) ;
  200.     void disposeregion(void) ;
  201.     BOOL addregion(short l, short t, short w, short h) ;
  202.     void installclip(void) ;
  203.     void removeclip(void) ;
  204.  
  205.     // Pointer Routines
  206.     void setpointer( UWORD *pointer, long height,
  207.         long width, long xOffset, long yOffset ) ;
  208.     void clearpointer() ;
  209.  
  210.     // Area Routines
  211.     short initarea(short w, short h, int size=1000) ;
  212.     void freearea() ;
  213.     long areaellipse(long xCenter, long yCenter, long a, long b ) ;
  214.     long areamove( long x, long y ) ;
  215.     long areadraw( long x, long y ) ;
  216.     long areaend() ;
  217.     BOOL flood( unsigned long mode, long x, long y ) ;
  218.  
  219.     // BackGround Drawing routines
  220.     void setbgrp(RastPort *brp) ;
  221.     void clearbgrp() ;
  222.  
  223.     void flushbg(int x, int y, int w, int h, int mode=0xC0) ;
  224.  
  225.     // Refresh routines
  226.     void beginrefresh() ;
  227.     void endrefresh(BOOL end) ;
  228.     void refreshwindowframe() ;
  229.  
  230. } ;
  231.  
  232. inline void window::fok(gadget *g, unsigned long classe, unsigned short code)
  233. {
  234.     okflag = TRUE; active = FALSE ; emode = 0 ; applique = FALSE ;
  235. }
  236.  
  237. inline void window::fcancel(gadget *g, unsigned long classe, unsigned short code)
  238. {
  239.     okflag = FALSE; active = FALSE ; emode = 0 ; applique = FALSE ;
  240. }
  241.  
  242. inline void window::fapply(gadget *g, unsigned long classe, unsigned short code)
  243. {
  244.     okflag = TRUE; active = FALSE ; emode = 0 ; applique = TRUE ;
  245. }
  246.  
  247. inline void window::handlevkey(USHORT code)
  248. {
  249.     if (code == 0x0D) {
  250.         g->selectgadget(g->getcount()-2, FALSE) ;
  251.     }
  252.     else if (code == 0x1B) {
  253.         g->selectgadget(g->getcount()-1, FALSE) ;
  254.     }
  255.     else
  256.         g->parsegadgets(code) ;
  257. }
  258.  
  259. inline void window::handlerawkey(USHORT code)
  260. {
  261. }
  262.  
  263. inline void window::handlemousebuttons(USHORT code, WORD x, WORD y, UWORD qualifier)
  264. {
  265. }
  266.  
  267. #if !defined( CLASS_WINDOW_INLINES_H ) && !defined( NO_CLASS_WINDOW_INLINES )
  268. #include "window_inlines.h"
  269. #endif
  270.  
  271. typedef void (window::*WFUNC)(gadget *, unsigned long, unsigned short) ;
  272. #endif
  273.  
  274.